﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace WindowsGame1.gamePlugins.menu
{
    class IngameMenu
    {
        public enum optionmenu { none, singleplayer, multiplayer, resume, calibrate, quit }
        public optionmenu clicked = optionmenu.none;
        Button bSinglePlayer, bMultiPlayer, bResume, bCalibrate, bExit;
        SpriteFont myFont;
        Texture2D texture, texture2, texture3, texture4, texture5,
                    texture_pressed, texture2_pressed, texture3_pressed, texture4_pressed, texture5_pressed;
        
        public IngameMenu(ContentManager Content, SpriteBatch spriteBatch)
        {
            texture = Content.Load<Texture2D>("buttons/Singleplayer");
            texture_pressed = Content.Load<Texture2D>("buttons/SingleplayerIN");
            texture2 = Content.Load<Texture2D>("buttons/Multiplayer");
            texture2_pressed = Content.Load<Texture2D>("buttons/MultiplayerIN");
            texture3 = Content.Load<Texture2D>("buttons/Resume");
            texture3_pressed = Content.Load<Texture2D>("buttons/ResumeIN");
            texture4 = Content.Load<Texture2D>("buttons/Calibratie");
            texture4_pressed = Content.Load<Texture2D>("buttons/CalibratieIN");
            texture5 = Content.Load<Texture2D>("buttons/Quit");
            texture5_pressed = Content.Load<Texture2D>("buttons/QuitIN");

            myFont = Content.Load<SpriteFont>("Font");
            bSinglePlayer = new Button(texture, myFont, spriteBatch);
            bMultiPlayer = new Button(texture2, myFont, spriteBatch);
            bResume = new Button(texture3, myFont, spriteBatch);
            bCalibrate = new Button(texture4, myFont, spriteBatch);
            bExit = new Button(texture5, myFont, spriteBatch);

            bSinglePlayer.pressedTexture(texture_pressed);
            bMultiPlayer.pressedTexture(texture2_pressed);
            bResume.pressedTexture(texture3_pressed);
            bCalibrate.pressedTexture(texture4_pressed);
            bExit.pressedTexture(texture5_pressed);

            int halfDisplayWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / 2;
            int halfDisplayHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / 2;
            bSinglePlayer.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight - (texture.Height * 4));
            bMultiPlayer.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight - (texture.Height * 2));
            bResume.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight);
            bCalibrate.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight + (texture.Height * 2));
            bExit.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight + (texture.Height * 4));
        }

        public void update(GameTime gameTime)
        {
            int halfDisplayWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / 2;
            int halfDisplayHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / 2;
            bSinglePlayer.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight - (texture.Height * 4));
            bMultiPlayer.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight - (texture.Height * 2));
            bResume.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight);
            bCalibrate.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight + (texture.Height * 2));
            bExit.Location(halfDisplayWidth - (texture.Width / 2), halfDisplayHeight + (texture.Height * 4));
            
            bSinglePlayer.Update();
            bMultiPlayer.Update();
            bResume.Update();
            bCalibrate.Update();
            bExit.Update();

            if (bSinglePlayer.clicked)
            {
                clicked = optionmenu.singleplayer;
            }
            else if (bMultiPlayer.clicked)
            {
                clicked = optionmenu.multiplayer;
            }
            else if (bResume.clicked)
            {
                clicked = optionmenu.resume;
            }
            else if (bCalibrate.clicked)
            {
                clicked = optionmenu.calibrate;
            }
            else if (bExit.clicked)
            {
                clicked = optionmenu.quit;
            }

        }

        public void draw()
        {
            bSinglePlayer.Draw();
            bMultiPlayer.Draw();
            bResume.Draw();
            bCalibrate.Draw();
            bExit.Draw(); 
        }
    }
}
